// ReRemind
// Copyright (C) 2009, Avian Waves Software
// SEE LICENSE.TXT for software licensing information


#include "stdafx.h"

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
  return TRUE;
}

codeINSTALL_INIT Install_Init(HWND hwndParent, BOOL fFirstCall, BOOL fPreviouslyInstalled, LPCTSTR pszInstallDir)
{
  return codeINSTALL_INIT_CONTINUE;
}

codeINSTALL_EXIT Install_Exit(HWND hwndParent, LPCTSTR pszInstallDir, WORD cFailedDirs, WORD cFailedFiles, WORD cFailedRegKeys, WORD cFailedRegVals, WORD cFailedShortcuts)
{
  FILE *f = fopen("\\Windows\\StartUp\\StartReRemindSvc.lnk","w");
  if (f)
  {
    wchar_t lnk[MAX_PATH];
    wchar_t lnk2[MAX_PATH];
    _tcscpy(lnk, _T("\""));
    _tcscat(lnk, pszInstallDir);
    _tcscat(lnk, _T("\\StartReRemindSvc.exe\" silentwait"));
    
    size_t len = _tcslen(lnk);
    wsprintf(lnk2, L"%d#%s", len, lnk);
    
    fputws(lnk2,f);

    fclose(f);
  }
  
  ActivateService(_T("ReRemindSvc"),0);

  return codeINSTALL_EXIT_DONE;
} 

codeUNINSTALL_INIT Uninstall_Init(HWND hwndParent, LPCTSTR pszInstallDir)
{
  HANDLE hsvc = GetServiceHandle(_T("RER0:"), NULL, 0);
  if (hsvc != INVALID_HANDLE_VALUE)
  {
    DeregisterService(hsvc);
  }

  return codeUNINSTALL_INIT_CONTINUE;
} 

codeUNINSTALL_EXIT Uninstall_Exit(HWND hwndParent)
{
  return codeUNINSTALL_EXIT_DONE;
}